#include <iostream>
#include "MinFlow.h"
#include <fstream>
#include <vector>
using namespace std;

void readFile(vector<Cube>& cubes, string& word) {
ifstream in("in.txt", ifstream::in);
        if (!in.is_open()) 
        { 
                cout<<"File Error"<<endl;
                system("pause");
                exit(1);
        }
        int n;
        in>>word;
        in>>n;
		//cout<<n;
        for ( int i = 0; i < n; ++i ) {
                char cube[6];
                for ( int j = 0; j < 6; ++j ) {
                        in >> cube[j];
						
                }
				
                cubes.push_back(Cube(cube));
        }
        in.close(); 
}
int main() {
	vector<Cube> cubes;
	string word;
	readFile(cubes, word);
	cout<<word<<endl;
	for (int i=0; i<cubes.size(); i++) {
		for (int j=0; j<6; j++) {
			cout<<cubes[i].mLetters[j];
		}
		cout<<endl;
	}
	MinFlow minFlow;
	vector<int> cubesPath;
	cubesPath=minFlow.getFlow(cubes, word);
	if (cubesPath.size()==0) {
		cout<<"NO"<<endl;
	} else {
		cout<<"YES"<<endl;
		for (vector<int>::iterator itr=cubesPath.begin(); itr<cubesPath.end(); itr++) {
			cout<<*(itr)<<" ";
		}
		cout<<endl;
	}
	system("pause");
}